package
{
	import com.funyoo.component.container.Container;
	import com.funyoo.component.container.Direction;
	import com.funyoo.component.container.HBox;
	import com.funyoo.component.controlls.Button;
	import com.funyoo.component.controlls.ScrollBar;
	import com.funyoo.component.controlls.TextInput;
	import com.funyoo.component.core.Component;
	import com.funyoo.utils.drag.SCDragManager;
	import com.funyoo.utils.drag.core.IDragObjectAcceptAble;
	import com.funyoo.utils.drag.SCDragManager;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	import flash.text.TextFieldType;
	import flash.text.TextFormatAlign;
	import flash.utils.getTimer;
	
	/**
	 * ...
	 * @author Argus
	 */
	[SWF(width="500",height="500",backgroundColor="0xffff00")]
	public class Main extends Sprite
	{
		private var holder:Container;
		private var childHolder:Container;
		private var test:Component;
		
		public function Main():void
		{
			if (stage)
				init();
			else
				addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			//stage.addEventListener(MouseEvent.CLICK, handleStageClick);
			SCDragManager.instance.defaultContainer = stage;
			holder = new Container();
			holder.id = "root";
			/*holder.width = 500;
			holder.height = 500;*/
			holder.fillColor = 0x0000ff;
			holder.stickWithParent = true;
			holder.vCenter = 0;
			holder.hCenter = 0;
			stage.addChild(holder);
			childHolder = new Container();
			childHolder.id = "child";
			childHolder.width = 300;
			childHolder.height = 300;
			childHolder.fillColor = 0x00ff00;
			childHolder.stickWithParent = false;
			childHolder.vCenter = 0;
			childHolder.hCenter = 0;
			//holder.addChild(childHolder);
			removeEventListener(Event.ADDED_TO_STAGE, init);
			var loader:Loader = new Loader();
			var context:LoaderContext = new LoaderContext();
			context.applicationDomain = ApplicationDomain.currentDomain;
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoaderComplete);
			loader.load(new URLRequest("ss.swf"), context);
		}
		
		private function handleStageClick(e:MouseEvent):void 
		{
			if (stage.displayState == StageDisplayState.FULL_SCREEN)
			{
				stage.displayState = StageDisplayState.NORMAL;
			}else
			{
				stage.displayState = StageDisplayState.FULL_SCREEN;
			}
		}
		
		private function handleLoaderComplete(e:Event):void 
		{
			var bar:ScrollBar = new ScrollBar();
			bar.direction = Direction.HORIZONTAL;
			bar.width = 200;
			bar.height = 20;
			bar.bottom = 10;
			bar.right = 10;
			bar.scrollPosition = 1;
			holder.addChild(bar);
			var box:HBox = new HBox();
			box.id = "box";
			box.width = 300;
			box.height = 100;
			box.top = 10;
			box.left = 10;
			holder.addChild(box);
			var sc:Button = new Button();
			box.addChild(sc);
			sc.label = "NO";
			//sc.addEventListener(MouseEvent.MOUSE_DOWN, handleScMouseDown);
			
			var sss:Container = new Container();
			sss.width = 100;
			sss.height = 100;
			sss.fillColor = 0xff0000;
			box.addChild(sss);
			
		/*	var sb:SomeButton = new SomeButton();
			box.addChild(sb);
			sb.label = "YES";
			sc.fontColor = 0xff0000;
			sc.fontWeight = true;*/
			//sb.addEventListener(MouseEvent.MOUSE_DOWN, handleScMouseDown);
			var lb:TextInput = new TextInput();
			lb.width = 200;
			lb.height = 20;
			lb.top = 10;
			lb.left = 10;
			lb.text = "input here";
			lb.fontColor = 0xff0000;
			lb.fontWeight = true;
			box.addChild(lb);
		}
		
		private function handleScMouseDown(e:MouseEvent):void 
		{
			
			var sc:Component = e.currentTarget as Component;
		//	sc.styleLink = "TestBtn";
			//SomeButton(sc).label = "SHIT";
			sc.layoutEnable = false;
			SCDragManager.instance.doDrag(sc,"direct",releaseOutHandler);
		}
		private function releaseOutHandler(state:int):void
		{
			
		}
	}

}